package com.fs.entity;

import java.util.ArrayList;
import java.util.List;

public class Page<T> {
    /*
    -   List<对象>  行数据     select * from 表名  limit x,y;   x开始序号 = (当前页码-1)*页容量   y:页容量
    - 页码  前端传递
    - 总页数  :  总记录数 % 页容量 ==0? 总记录数/页容量: 总记录数/页容量 + 1
    - 总记录数: select count(1) from 表名
    - 页容量  前端传递
     */
    private List<T>  records  = new ArrayList<>();
    private int pageIndex;
    private int pageSize;
    /**
     * 总记录数
     */
    private long  totalCount;
    /**
     * 总页数
     */
    private long totalPages;

    public List<T> getRecords() {
        return records;
    }

    public void setRecords(List<T> records) {
        this.records = records;
    }

    public int getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(int pageIndex) {
        this.pageIndex = pageIndex;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public long getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(long totalCount) {
        this.totalCount = totalCount;
    }

    public long getTotalPages() {
        // 总记录数 % 页容量 ==0? 总记录数/页容量: 总记录数/页容量 + 1
        return this.totalCount % this.pageSize == 0?
                this.totalCount/this.pageSize:this.totalCount/this.pageSize+1;
    }
}
